﻿/***********************************************************************************************************************************
 *    Name: Job_Control.sql
 *  Author: Frank Figearo — http://www.sqlnerd.me/ — frank@sqlnerd.me
 * Summary:	
**/
SET IMPLICIT_TRANSACTIONS OFF; IF 0 < @@TRANCOUNT ROLLBACK;
USE msdb;
GO
-- handy job control t-sql commands
PRINT @@SERVERNAME;
EXECUTE msdb.dbo.sp_start_job  @job_name= '';
EXECUTE msdb.dbo.sp_stop_job   @job_name= '';
EXECUTE msdb.dbo.sp_update_job @job_name= '', @enabled= 0;	-- disable job
GO

-- enable all jobs
USE msdb;
DECLARE @tsql_command NVARCHAR(MAX)= N'';
SELECT @tsql_command+= N'EXECUTE msdb.dbo.sp_update_job @job_name= ''' + name + N''', @enabled= 1; ' FROM dbo.sysjobs;
EXECUTE (@tsql_command);
GO